﻿package Welsy4.Connect.business 
{
	
	import flash.net.URLVariables;
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.rpc.http.HTTPService;
	
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import Welsy4.Connect.vo.User;
	import Welsy4.Connect.vo.Meeting;
	import Welsy4.Connect.model.ConnectModel;
	
	public class MeetingDelegate 
	{
		
		private var responder : IResponder;
        private var service : Object;
                
        public function MeetingDelegate( responder : IResponder ){
            this.service = ServiceLocator.getInstance().getHTTPService("FakeAPI" );
            this.responder = responder;
        }
		
		public function reportMyMeeting():void {
		    // require you are logged in
			var request:URLVariables = new URLVariables("action=report-my-meetings&nocache="+ User.getLoginRequestlocaleTime());
			request.session = ConnectModel.getInstance().sessionCookie;
			var token : AsyncToken = HTTPService(service).send(request);
			token.addResponder(responder);
		}
		
		
		public function createMeeting(name:String, folder_id:String, date_begin:String, date_end:String, url_path:String):void {
			
			var updateRequest:URLVariables = new URLVariables("action=sco-update&type=meeting");
			
			//note: the folder-id is the sco-id of the user’s my-meetings folder.
			updateRequest.decode("name=" + name);
			updateRequest.decode("folder-id=" + folder_id);
			updateRequest.decode("date-begin=" + date_begin);
			updateRequest.decode("date-end=" + date_end);
			updateRequest.decode("url-path=" + url_path);
			updateRequest.decode("nocache=" + User.getLoginRequestlocaleTime());
			updateRequest.session = ConnectModel.getInstance().sessionCookie;
            
			var token : AsyncToken = HTTPService(service).send(updateRequest);
			token.addResponder(responder);	
		}
		public function getMeetingRoomURL():void {
		    // require you are logged in	
		}
		
		public function updateMeeting(meeting:Meeting):void {
		    var updateRequest:URLVariables = new URLVariables("action=sco-update&type=meeting");
			
			updateRequest.decode("sco-id="+ meeting.sco_id);
			updateRequest.description = meeting.description;
			
			if (meeting.date_begin != null) {
				updateRequest.decode("date-begin=" + meeting.date_begin);
			}
			
			if (meeting.date_end != null) {
			    updateRequest.decode("date-end=" + meeting.date_end);
			}
			
			updateRequest.decode("nocache=" + User.getLoginRequestlocaleTime());
			updateRequest.session = ConnectModel.getInstance().sessionCookie;
			
			var token : AsyncToken = HTTPService(service).send(updateRequest);
			token.addResponder(responder);	
			
		}
		
		public function deleteMeeting(meeting:Meeting):void {
		    var deleteRequest:URLVariables = new URLVariables("action=sco-delete");
			deleteRequest.decode("sco-id=" + meeting.sco_id);
			deleteRequest.decode("nocache=" + User.getLoginRequestlocaleTime());
			deleteRequest.session = ConnectModel.getInstance().sessionCookie;
			
			var token : AsyncToken = HTTPService(service).send(deleteRequest);
			token.addResponder(responder);	
		}
		
	}
	
}